import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

/* Layout */
import Layout from "@/layout";
const redirect = (resolve) => require(["@/views/redirect/index"], resolve);
const login = (resolve) => require(["@/views/login/index"], resolve);
const authRedirect = (resolve) =>
  require(["@/views/login/auth-redirect"], resolve);
const notFound = (resolve) => require(["@/views/error-page/404"], resolve);
const errorPage = (resolve) => require(["@/views/error-page/401"], resolve);
const drowMap = (resolve) => require(["@/views/drow-map/index"], resolve);
const Index = (resolve) => require(["@/views/dashboard/index"], resolve);
const pavilionBasic = (resolve) =>
  require(["@/views/pavilion-basic/index"], resolve);
const pavilionBuilding = (resolve) =>
  require(["@/views/pavilion-building/index"], resolve);
const pavilionFloor = (resolve) =>
  require(["@/views/pavilion-floor/index"], resolve);
const pavilionPoint = (resolve) =>
  require(["@/views/pavilion-point/index"], resolve);
const pavilionRouters = (resolve) =>
  require(["@/views/pavilion-routers/index"], resolve);
const booksmsg = (resolve) => require(["@/views/books-msg/index"], resolve);
const catalogue = (resolve) =>
  require(["@/views/books-msg/catalogue"], resolve);
const booksSyc = (resolve) => require(["@/views/books-syc/index"], resolve);
const orientationDriving = (resolve) =>
  require(["@/views/orientation-driving/index"], resolve);
const orientationMsg = (resolve) =>
  require(["@/views/orientation-msg/index"], resolve);
const orientationRules = (resolve) =>
  require(["@/views/orientation-rules/index"], resolve);
const orientationSyc = (resolve) =>
  require(["@/views/orientation-syc/index"], resolve);
const extendPanorama = (resolve) =>
  require(["@/views/extend-panorama/index"], resolve);
const extendModel = (resolve) =>
  require(["@/views/extend-model/index"], resolve);
const systemFile = (resolve) => require(["@/views/system-file/index"], resolve);
const systemUser = (resolve) => require(["@/views/system-user/index"], resolve);
const systemMenu = (resolve) => require(["@/views/system-menu/index"], resolve);
const systemConfiguration = (resolve) =>
  require(["@/views/system-configuration/index"], resolve);

export const constantRoutes = [
  {
    path: "/redirect",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "/redirect/:path(.*)",
        // component: () => import("@/views/redirect/index"),
        component: redirect,
      },
    ],
  },
  {
    path: "/login",
    component: login,
    // component: () => import("@/views/login/index"),
    hidden: true,
  },
  {
    path: "/auth-redirect",
    component: authRedirect,
    hidden: true,
  },
  {
    path: "/404",
    component: notFound,
    hidden: true,
  },
  {
    path: "/401",
    component: errorPage,
    hidden: true,
  },
  {
    path: "/drow-map",
    component: drowMap,
    hidden: true,
  },
  {
    path: "/",
    component: Layout,
    redirect: "/dashboard",
    children: [
      {
        path: "dashboard",
        component: Index,
        name: "首页",
        meta: { title: "首页", icon: "icon-arrdown", affix: true },
      },
    ],
  },
  {
    path: "/pavilion",
    component: Layout,
    redirect: "/pavilion/basic",
    name: "pavilion",
    alwaysShow: true,
    meta: {
      title: "虚拟馆管理",
      icon: "el-icon-school",
      roles: ["admin"],
    },
    children: [
      {
        path: "basic",
        component: pavilionBasic,
        name: "basic",
        meta: { title: "基础信息", icon: "el-icon-edit-outline" },
      },
      {
        path: "building",
        component: pavilionBuilding,
        name: "building",
        meta: { title: "楼栋管理", icon: "el-icon-office-building" },
      },
      {
        path: "floor",
        component: pavilionFloor,
        name: "floor",
        meta: { title: "地图管理", icon: "el-icon-picture" },
      },
      {
        path: "point",
        component: pavilionPoint,
        name: "point",
        meta: { title: "点位管理", icon: "el-icon-location" },
      },
      {
        path: "routers",
        component: pavilionRouters,
        name: "routers",
        meta: { title: "路径管理", icon: "el-icon-position" },
      },
    ],
  },
  {
    path: "/books",
    component: Layout,
    redirect: "/books/msg",
    name: "books",
    alwaysShow: true,
    meta: {
      title: "图书管理",
      icon: "el-icon-reading",
      roles: ["admin"],
    },
    children: [
      {
        path: "msg",
        component: booksmsg,
        name: "msg",
        meta: { title: "图书信息管理", icon: "el-icon-tickets" },
        children: [
          {
            path: "catalogue",
            component: catalogue,
            name: "catalogue",
            meta: {
              title: "资产目录",
              icon: "el-icon-document-copy",
              activeMenu: "/books/msg",
            },
            hidden: true,
          },
        ],
      },
      {
        path: "syc",
        component: booksSyc,
        name: "syc",
        meta: { title: "图书同步管理", icon: "el-icon-sort" },
      },
    ],
  },
  {
    path: "/orientation",
    component: Layout,
    redirect: "/orientation/driving",
    name: "orientation",
    alwaysShow: true,
    meta: {
      title: "定位管理",
      icon: "el-icon-place",
      roles: ["admin"],
    },
    children: [
      {
        path: "driving",
        component: orientationDriving,
        name: "driving",
        meta: { title: "架层信息管理", icon: "el-icon-tickets" },
      },
      {
        path: "locationmsg",
        component: orientationMsg,
        name: "locationmsg",
        meta: { title: "定位信息管理", icon: "el-icon-tickets" },
      },
      {
        path: "rules",
        component: orientationRules,
        name: "rules",
        meta: { title: "定位规则管理", icon: "el-icon-document-checked" },
      },
      {
        path: "locationsyc",
        component: orientationSyc,
        name: "locationsyc",
        meta: { title: "定位同步管理", icon: "el-icon-sort" },
      },
    ],
  },
  {
    path: "/extend",
    component: Layout,
    redirect: "/extend/panorama",
    name: "extend",
    alwaysShow: true,
    meta: {
      title: "扩展功能管理",
      icon: "el-icon-folder-add",
      roles: ["admin"],
    },
    children: [
      {
        path: "panorama",
        component: extendPanorama,
        name: "panorama",
        meta: { title: "全景图管理", icon: "el-icon-aim" },
      },
      {
        path: "model",
        component: extendModel,
        name: "model",
        meta: { title: "模型管理", icon: "el-icon-s-grid" },
      },
    ],
  },
  {
    path: "/system",
    component: Layout,
    redirect: "/system/file",
    name: "system",
    alwaysShow: true,
    meta: {
      title: "系统管理",
      icon: "el-icon-s-platform",
      roles: ["admin"],
    },
    children: [
      {
        path: "configuration",
        component: systemConfiguration,
        name: "configuration",
        meta: { title: "配置文件管理", icon: "el-icon-folder" },
      },
      {
        path: "file",
        component: systemFile,
        name: "file",
        meta: { title: "文件资源管理", icon: "el-icon-folder" },
      },
      {
        path: "user",
        component: systemUser,
        name: "user",
        meta: { title: "用户管理", icon: "el-icon-s-custom" },
      },
      {
        path: "menu",
        component: systemMenu,
        name: "menu",
        meta: { title: "菜单管理", icon: "el-icon-menu" },
      },
    ],
  },
];

export const asyncRoutes = [
  // 404 page must be placed at the end !!!
  { path: "*", redirect: "/404", hidden: true },
];

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    mode: "hash",
    routes: constantRoutes,
  });

const router = createRouter();

export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;
